#ifndef BEZIER_H_
#include "Bezier.h"
#endif

using namespace std;
using std::vector;

Bezier :: Bezier(GLuint program, GLfloat points[TAMMATBEZIER][TAMMATBEZIER][3]){
	this->programHandle = program;
 loadPatches(points);
}

Bezier :: ~Bezier(){

 for(size_t i=0 ; i<patches.size() ; i++ )
	delete(patches[i]);
}

void Bezier :: loadPatches(GLfloat points[TAMMATBEZIER][TAMMATBEZIER][3]){

 for(size_t j=0 ; (j<TAMMATBEZIER)&&((j+TAMPATCHBEZIER-1)<TAMMATBEZIER) ; j+=(TAMPATCHBEZIER-1) ){
	for(size_t i=0 ; (i<TAMMATBEZIER)&&((i+TAMPATCHBEZIER-1)<TAMMATBEZIER) ; i+=(TAMPATCHBEZIER-1)){

		GLfloat aux[TAMPATCHBEZIER][TAMPATCHBEZIER][3];
 		for(size_t v=0 ; v<TAMPATCHBEZIER ; v++ )
			for(size_t u=0 ; u<TAMPATCHBEZIER ; u++ )
				for(size_t w=0 ; w<3 ; w++ )
 					aux[u][v][w] = points[u+i][v+j][w];		
		//show(aux);

		BezierCubSurf* surf = new BezierCubSurf(this->programHandle, aux);
		patches.push_back(surf);
	}
 }
}

void Bezier :: drawNormals(glm::mat4 mat){
 for(size_t i=0 ; i<patches.size() ; i++ ){
	(patches[i])->drawNormals(mat);
 }
}

void Bezier :: drawSurface(glm::mat4 mat){
 for(size_t i=0 ; i<patches.size() ; i++ ){
	(patches[i])->drawSurface(mat);
 }
}

void Bezier :: drawControlPoints(){
 for(size_t i=0 ; i<patches.size() ; i++ ){
	(patches[i])->drawControlPoints();
 }
}

void Bezier :: show(GLfloat aux[TAMPATCHBEZIER][TAMPATCHBEZIER][3]){
 cout << "\nMat:\n";
 for(size_t i=0 ; i<TAMPATCHBEZIER ; i++ ){
	for(size_t j=0 ; j<TAMPATCHBEZIER ; j++ )
		cout << " {" << aux[i][j][0] << ";" << aux[i][j][1] << ";" << aux[i][j][2] << "} \t";
	cout << "\n";
 }
 cout << "\n";
}
